package com.agiantii.ablog.handler.article.chain.impl;


import com.agiantii.ablog.handler.article.chain.BaseContentHandler;
import com.agiantii.ablog.pojo.dto.PostDTO;
import com.agiantii.ablog.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class TitleHandler extends BaseContentHandler {
    private static final List<String> SENSITIVE_WORDS = Arrays.asList("傻", "笨蛋", "白痴","asshole");
    @Override
    public boolean handle(PostDTO content) {
        if(StringUtil.isEmpty(content.getTitle())){
            throw new IllegalArgumentException("孩子 你是不是忘记写标题了？");
        }
        for(String word:SENSITIVE_WORDS){
            if(content.getTitle().contains(word)){
                throw new IllegalArgumentException("标题中不能包含敏感词汇："+word);
            }
        }
        return handleNext(content);
    }

}
